using System;
using System.Text;
using Microsoft.SPOT;

namespace NetduinoHappyHour.Util
{
    /// <summary>
    /// holds an actual overall status of the system
    /// Written by: Salvador Richter
    /// Appache License Version 2.0 
    /// </summary>
    class SystemStatus
    {
        private static SystemStatus _instance = null;

        private string _defaultMessage = "nothing special";
        private StringBuilder _builder = new StringBuilder();
        private int _maxMessageSize = 4000;

        /// <summary>
        /// private constructor to avoid instantiation. 
        /// inside constructor all properties are set with default values
        /// </summary>
        private SystemStatus() 
        {
        }

        public void AddMessage(string Message)
        {
            if (_builder.Length+Message.Length > _maxMessageSize)
            {
                _builder.Remove(0, Message.Length);
            }
            _builder.AppendLine(Message);
        }

        public string GetMessage()
        {
            if (_builder.Length > 0)
            {
                return _builder.ToString();
            }
            else
            {
                return _defaultMessage;
            }
        }

        public void Clear()
        {
            _builder.Clear();
        }

        public static SystemStatus Instance()
        {
            if (_instance == null)
            {
                _instance = new SystemStatus();
            }
            return _instance;
        }
    }
}
